<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑主题--管理后台</title>
    <link th:href="@{/css/admin.css}" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="main">
    <div th:replace="admin/common :: #top"></div>
    <div th:replace="admin/common :: #opt_list"></div>
    <div id="opt_area">
        <span th:if="${error!=null}" th:text="${error}" style="color: red"></span>
        <ul class="classlist">

            <li th:each="topic:${topics}">
                    <label th:text="${topic.tname}"></label>
                &nbsp;&nbsp;&nbsp;&nbsp; <a th:href="@{/topic/toupdate(tid=${topic.tid})}">修改</a>
                &nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp; <!--<a th:href="@{/topic/delete(tid=${topic.tid})}">删除</a>-->
                <a href="javascript:;" th:id="${topic.tid}" onclick="del(this)">删除</a>
            </li>
        </ul>
    </div>
    <div th:replace="admin/common :: #footerbar"></div>
</div>

<script th:src="@{/js/jquery-1.8.3.min.js}"></script>
<script type="text/javascript">
    function  del(obj){
        var tid = obj.getAttribute("id")
        if(confirm("确定删除？")){
            $.ajax({
                url:"/newschina/topic/newsexists?tid="+tid,
                type:"get",
                dataType:"json",
                success:function (data){
                    //alert(data.result);
                    if(data.result == "true"){
                        alert("该主题下有新闻，不能删除！")
                    }else {
                        location.href="/newschina/topic/delete/?tid="+obj.getAttribute("id");
                    }
                }
            })
            //location.href="/newschina/topic/delete/?tid="+obj.getAttribute("id");
        }
    }
</script>
</body>
</html>	